package hlhj.fhp.checkpoint.atys

import android.widget.RadioButton
import android.widget.Toast
import hlhj.fhp.checkpoint.BaseAty
import hlhj.fhp.checkpoint.R
import hlhj.fhp.checkpoint.iview.GetCashView
import hlhj.fhp.checkpoint.javaBean.MyBaseBean
import hlhj.fhp.checkpoint.presenter.GetCashPresenter
import hlhj.fhp.checkpoint.utils.ToastUtils
import kotlinx.android.synthetic.main.aty_getcash.*
import kotlinx.android.synthetic.main.lo_pub_head.*

/**
 * Created by Never Fear   on 2018\11\12 0012.
Never More....
 */
class GetCashAty :BaseAty<GetCashView,GetCashPresenter>(), GetCashView {
    private var type=0
    override fun initView() {
        tvTittle.setText("提现账户")
        val button = rgType.getChildAt(0) as RadioButton
        button.isChecked=true
        tv1.text="可提现金额 ${intent.getStringExtra("all")} 元"
    }
    override fun logicStart() {
    }

    override fun setListener() {
        btGetCash.setOnClickListener {
            if (etAccount.text.toString().isEmpty()){
                ToastUtils.toast("请输入账号",this)
                return@setOnClickListener
            }
            if (type==0){
                ToastUtils.toast("请选择账户类型",this)
                return@setOnClickListener
            }
            if (etMoney.text.isEmpty()){
                ToastUtils.toast("请输入提现金额",this)
                return@setOnClickListener
            }
            if (etMoney.text.toString().toFloat()<100f){
                ToastUtils.toast("提现金额不能小于100",this)
                return@setOnClickListener
            }
            presenter?.getCash(type,etMoney.text.toString(),etAccount.text.toString(),this)
        }
        btAll.setOnClickListener {
            etMoney.setText(intent.getStringExtra("all"))
        }
        tv1.setOnClickListener {

        }
        rgType.setOnCheckedChangeListener { group, checkedId ->
            when(checkedId){
                R.id.rbWx->{
                    type=1
                }
                R.id.rbAli->{
                    type=2
                }
            }
        }
    }
    override fun setGetCashResult(myBaseBean: MyBaseBean) {
        ToastUtils.toast("提现申请成功",this)
        setResult(-1)
        finish()
    }

    override fun bindView(): GetCashView {
        return this
    }

    override fun createPresenter(): GetCashPresenter {
        return GetCashPresenter()
    }

    override val contentId: Int= R.layout.aty_getcash
}